﻿using Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Utility;
using System.Utility.DBMS;
using System.Utility.Messaging;
using System.Utility.UI;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UI
{
    public partial class AddUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PopulateUserRoles();

        }

        private void PopulateUserRoles()
        {
            ddRoleType.DataSource = DBHelper.GetDataset("GetUserRoles");
            ddRoleType.DataTextField = "Type";
            ddRoleType.DataValueField = "Type";

            ddRoleType.DataBind();
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                DBHelper.ExcuteProc("AddUser", new object[] { txtUserName.Value, txtEmail.Value, txtPass.Value, txtStore.Value, txtFax.Value, txtContcatPerson.Value, txtTelephone.Value,"DealershipStaff" });               

            }
            catch (Exception ex)
            {
                MessageUtility.LogAndGetMessageCode(ex);
                PageUtility.RegisterClientScriptBlockByMessageId(this, "GE0001");
            }
            PageUtility.RefreshByType(new Control[] {txtUserName, txtEmail, txtPass, txtStore, txtFax, txtContcatPerson, txtTelephone });
            PageUtility.RegisterClientScriptBlockByMessageId(this, "GE0001");
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            PageUtility.RefreshByType(new Control[] { txtUserName, txtEmail, txtPass, txtStore, txtFax, txtContcatPerson, txtTelephone });
        }
    }
}